// Copyright CengJia.  Year : 2023

using System;
using System.Collections.Generic;
using System.IO;
using UnrealBuildTool;

public class WebEdge : ModuleRules
{
	private string ThirdPartyPath
	{
		get { return Path.Combine(ModuleDirectory, "../ThirdParty"); }
	}
	private string ProjectPath
	{
		get { return Path.Combine(PluginDirectory, "../../"); }
	}
    public WebEdge(ReadOnlyTargetRules Target) : base(Target)
    {
	    if (Target.Platform == UnrealTargetPlatform.Win64)
		{
			bEnableUndefinedIdentifierWarnings = false;
			PublicIncludePaths.Add(  Path.Combine(ThirdPartyPath, "Edge/include") );
			PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Edge/lib/WebView2Loader.dll.lib"));
			PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Edge/lib/WebView2LoaderStatic.lib"));
			if (Target.Configuration == UnrealTargetConfiguration.Debug)
			{
				PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Edge/lib/Debug/EdgeUELib.lib"));
            }
			else
			{
				PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Edge/lib/Release/EdgeUELib.lib"));
			}
			PublicDelayLoadDLLs.Add("WebView2Loader.dll");
			
		}
	    
	    string SrcWebView2LoaderDll = Path.Combine(ThirdPartyPath, "Edge/dll/WebView2Loader.dll");
	    string DstWebView2LoaderDll = Path.Combine(ProjectPath, "Binaries/Win64/WebView2Loader.dll");
	    if (!File.Exists(DstWebView2LoaderDll))
	    {
		    if(!Directory.Exists( Path.Combine(ProjectPath, "Binaries/Win64/")))
			    Directory.CreateDirectory(Path.Combine(ProjectPath, "Binaries/Win64/"));
		    File.Copy(SrcWebView2LoaderDll,DstWebView2LoaderDll);
	    }
	    RuntimeDependencies.Add(DstWebView2LoaderDll);
	    
		PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
			}
			);
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				"CoreUObject",
				"Slate",
				"SlateCore",
				"UMG",
				"Engine",
				"InputCore",
				"RHI",
				"Json"
				// ... add private dependencies that you statically link with here ...	
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);
	}
}
